using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Resources;
using System.Reflection;
using System.Threading;
using System.Diagnostics;
using Microsoft.BizTalk.Component.Interop;
using Microsoft.BizTalk.TransportProxy.Interop;
using Microsoft.XLANGs.BaseTypes;

namespace Microsoft.Samples.BizTalk.Adapter.Tcp.Send
{
    /// <summary>
    ///     This class implements a send adapter in BizTalk.
    /// </summary>
    /// <author>
    ///     Paul Brown
    /// </author>
    public partial class SendAdapter : IBaseComponent,
                                       IBTTransport,
                                       IPersistPropertyBag,
                                       IBTTransportControl,
                                       IBTBatchTransmitter,
                                       IAdapter
    {
        #region IAdapter Members

        /// <summary>
        ///     This property returns a reference to the trace switch used by the adapter.
        /// </summary>
        public TraceSwitch TraceSwitch
        {
            get { return (this._sendSwitch); }
        }

        /// <summary>
        ///     This property returns a reference to the trace switch used by the adapter when sending or receiving data over the socket.
        /// </summary>
        public TraceSwitch SocketTraceSwitch
        {
            get { return (this._socketSwitch); }
        }

        /// <summary>
        ///     This property returns a reference to the transport proxy associated with this adapter.
        /// </summary>
        public IBTTransportProxy TransportProxy
        {
            get { return (this._proxy); }
        }

        /// <summary>
        ///     This property returns a reference to the work dispatcher.
        /// </summary>
        public Dispatcher Dispatcher
        {
            get { return (this._dispatcher); }
        }

        /// <summary>
        ///     This property returns a reference to the folder where dead messages that cannot be delivered to BizTalk are saved.
        /// </summary>
        public string DeadMessageFolder
        {
            get { return (this._deadMessageFolder); }
        }

        /// <summary>
        ///     This handler is called whenever a part of the adapter gets a catastrophic error that it cannot handle
        ///     which causes this handler to effectively restart the adapter.
        /// </summary>
        public void RestartAdapter(Exception e)
        {
            // Stop the dispatcher
            this._dispatcher.Stop();
            this._dispatcher.Dispose();

            // Re-initialize adapter state
            this.ReInitialize();
        }

        #endregion
    }
}
